<!DOCTYPE html>
<html>
<head>
<include file="Include:meta" />
<title>会议模板管理-目的地运营集团数据管理平台</title>
<include file="Include:style" />
</head>
<body>
<include file="Include:header" />
<include file="Include:left" />
<div id="main">
	<div class="crumbs">
		<div class="crumbs-text">会议模板管理 > 编辑会议模板</div>
	</div>
	<div id="content">
		<form action="__APP__/Index/meeting_minutes_module_edit" method="post" enctype="multipart/form-data">
		<input type="hidden" name="action" value="edit">
		<input type="hidden" name="id" value="{$result['id']}">
		<input type="hidden" name="center_ids" value="{$center_ids}">
			<div class="form-main">
				<div class="form-title">编辑会议模板</div>
				<if condition="get_permission('HY',NULL,1)">
				<if condition="$result['edit'] eq 1">
					<div class="form-item">
						<div class="input-label"><span class="asterisk">*</span>所属中心</div>
						<div class="input-item">
							<select name="center_id" class="form-control required-selt" autocomplete="off">
								<foreach name="center_list" item="vo">
									<option value="{$vo['id']}" <if condition="$result['center_id'] eq $vo['id']">selected</if>>{$vo['first_name']}</option>
								</foreach>
							</select>
							<span class="error-item">必填项</span>
						</div>
					</div>
				<else/>
					<div class="form-item">
						<div class="input-label">所属中心</div>
						<div class="input-item">
							{$result['center_name']}
						</div>
					</div>
				</if>
				</if>
				<div class="form-item">
					<div class="input-label">会议模板</div>
					<div class="input-item">
						<input type="text" name="module_name" class="form-control required-text" autocomplete="off" value="{$result['module_name']}">
						<span class="error-item">必填项</span>
						<div class="hide">
							<select name="p_type" class="form-control select-add" autocomplete="off">
								<option value="-10" selected>请选择</option>
								<foreach name="module" item="vo">
									<option value="{$vo['id']}">{$vo['module_name']}</option>
								</foreach>
							</select>
						</div>
						<span class="error-item">该会议模板已存在</span>
					</div>
				</div>
				<div class="form-item">
					<div class="input-label">会议人员</div>
					<div class="input-item">
						<button type="button" class="is_all btn is_all_btn">选择用户</button>
						<span class="error-item">请选择用户</span>
						<div class="users-list"><strong>已选用户：</strong>{$result['users']}</div>
						<input type="hidden" name="uids" class="uids-input" value="{$result['uids']}" autocomplete="off"/>
						<input type="hidden" name="users" class="users-input" value="{$result['users']}" autocomplete="off"/>
						<button type="button" class="btn sort-btn">调整发言顺序</button>
					</div>
				</div>
			</div>
			<div class="form-btn-item"><button class="btn submit" type="submit">提交</button><button class="btn btn-default goback" type="button">返回</button></div>
		</form>
	</div>
</div>
<!--选择用户-->
<div class="modal fade" id="selectuser-modal">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<h4>选择用户</h4>
				<i class="fa fa-times" aria-hidden="true" data-dismiss="modal"></i>
			</div>
			<div class="modal-body">
				<foreach name="user_list" item="do">
					<div class="department">
						<label><input class="department-checkbox" type="checkbox" autocomplete="off" />{$do['name']}</label>
					</div>
					<ul>
						<foreach name="do['user']" item="uo">
							<li>
								<label><input class="user-checkbox" type="checkbox" value="{$uo['id']}" autocomplete="off" />{$uo['username']}</label>
							</li>
						</foreach>
					</ul>
				</foreach>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn user-affirm">确认</button><button type="button" class="btn btn-default user-cancel" data-dismiss="modal">取消</button>
			</div>
		</div>
	</div>
</div>
<!--排序弹框-->
<div class="sort-box hide">
	<div class="title">分类排序</div>
	<div class="sort-main">
		<ul></ul>
	</div>
	<div class="btn-item">
		<a href="javascript:;" class="btn sort-confirm">确认</a>
		<a href="javascript:;" class="btn btn-default sort-cancel">取消</a>
	</div>
</div>
<include file="Include:javascript" />
<script type="text/javascript" src="__PUBLIC__/js/user_select.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/ddsort.js"></script>
<script type="text/javascript">
$(function(){
	//人员选择
	$(".is_all").click(function(){
		$("#selectuser-modal").modal("show");
	});
	//提交验证
	$(".submit").click(function(){
		var tag = false;
		
		$(".required-text").each(function(){
			var val = $(this).val();
			if(val==""){
				$(this).next(".error-item").show();
				tag = true;
			}
		});
		$("select.select-add").each(function(){
			var $this = $(this),
				val = $this.val(),
				text = $this.parents('.input-item').find(".required-text").val();
			
			$this.find("option").each(function(){
				if($(this).text()==text){
					$this.parents('.input-item').find(".error-item").eq(1).show()
					tag = true;
					return false;
				}
			});
		});
		if($("[name='users']").val()==""){
			$(".is_all").next(".error-item").show();
			tag = true;
		}
		$("select.required-selt").each(function(){
			var $val = $(this).val();
			
			if($val==-10){
				$(this).nextAll(".error-item").eq(0).show();
				tag = true;
			}
		});
		if(tag){
			return false;
		}
	});
	//隐藏错误提示
	$(".required-text").focus(function(){
		$(this).nextAll(".error-item").hide();
	});
	$(".is_all_btn").click(function(){
		$(this).siblings(".error-item").hide();
	});
	$("select.required-selt").change(function(){
		$(this).nextAll(".error-item").hide();
	});
	$(".sort-btn").click(function(){
		$("body").append("<div class='sort-mask'></div>");
		var box = $(".sort-box"),
			ul = $(".sort-box").find(".sort-main ul"),
			users = $("[name='users']").val(),
			uids = $("[name='uids']").val(),
			arr = users.split(','),
			att = uids.split(','),
			html = "";
		for(var i=0;i<arr.length;i++){
			html+= "<li uid='"+att[i]+"'>"+arr[i]+"</li>"
		}
		ul.html(html);
		box.show();
		sortResize();
	});
	//排序框宽度自适应
	$(window).resize(function(){
		if($(".sort-box").is(":visible")){
			sortResize();
		}
	});
	function sortResize(){
		var box = $(".sort-box"),
			main = box.find(".sort-main"),
			ul = main.find("ul");
		main.width("auto");
		ul.width("auto");
		var w = main.width();
		ul.width(w);
		if(ul.outerHeight() > main.outerHeight()){
			main.width(w+18);
			box.width(w+18);
			$("#main").css("padding-left",w+18);
		}else{
			box.width(w);
			$("#main").css("padding-left",w);
		}
	}
	//排序确认
	$(".sort-confirm").on("click",function(){
		var box = $(this).parents(".sort-box"),
			mid_array = [],
			id = $("[name='id']").val();
		box.find(".sort-main li").each(function(i){
			mid_array[i] = $(this).attr("uid");
		});
		$.ajax({
			type:"POST",
			async:false,
			dataType:"json",
			url:"__APP__/Index/meeting_minutes_module_audit",
			data:{"uids":mid_array,"id":id,"action":"edit"},
			success:function(data){
				$("[name='uids']").val(data.uids);
				$("[name='users']").val(data.users);
				$(".users-list").html("<strong>已选用户：</strong>"+data.users+"")
				$(".sort-box").hide();
				$(".sort-mask").remove();
				$("#main").css("padding-left",100);
			}
		});
	});
	//排序取消
	$(".sort-cancel").on("click",function(){
		$(".sort-box").hide();
		$(".sort-mask").remove();
		$("#main").css("padding-left",100);
	});
	//调用排序插件
	$(".sort-box").find(".sort-main").DDSort({
		target:'li',
		floatStyle:{
			'border-bottom':'0',
			'background-color':'#f49900',
			'box-shadow':'0 0 3px #ddd',
			'list-style-type':'disc'
		},
		cloneStyle:{
			'background-color':'#ddd'
		}
	});
});
</script>
</body>
</html>